<template>
  <el-container>
    <el-header style="position: relative;height: 70px; width: 100%;padding:0 0 1px 0;border-bottom: 1px solid #cacaca;">
      <div class="header_1">
        <P class="p1">报刊订阅订阅中心</P>
        <p class='p2'>dingyuezhongxin</p>
      </div>
      <div
        class="header_2"
        v-if="loginStatus"
      >
        <el-menu mode="horizontal">
          <el-menu-item
            v-for="(value,index) in menulist"
            :key="index"
            color='#000000'
            text-size='10px'
            @click="toPage(value)"
          >
            {{value.menuname}}
          </el-menu-item>
        </el-menu>
      </div>
      <div class='header_3'>
        <el-dropdown>
          <span class="el-dropdown-link">
            订阅咨询<i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <!-- <el-dropdown-item>黄金糕</el-dropdown-item>
            <el-dropdown-item>狮子头</el-dropdown-item>
            <el-dropdown-item>螺蛳粉</el-dropdown-item>
            <el-dropdown-item disabled>双皮奶</el-dropdown-item>
            <el-dropdown-item divided>蚵仔煎</el-dropdown-item> -->
          </el-dropdown-menu>
        </el-dropdown>
        <!-- <el-button
          type="danger"
          round
          icon="el-icon-user"
        >{{ loginText }}</el-button> -->
        <!-- <span
          v-if="loginStatus"
          class="logoutText"
          @click="logout"
        >退出</span> -->
        <div class="login_box">
          <i class="el-icon-user"></i>
          <span class="userText">{{ loginText }}</span>
          <span
            v-if="loginStatus"
            class="logoutText"
            @click="logout"
          >退出</span>
        </div>
      </div>
    </el-header>
    <el-main>
      <router-view @set-name="setName"></router-view>
    </el-main>
    <el-footer></el-footer>
  </el-container>
</template>
<script>
export default {
  name: 'layout-index',
  data() {
    return {
      loginText: '登录/注册',
      loginStatus: false,
      menulist: [
        {
          menuname: '立即订阅',
          menuid: 1,
          menuurl: '/pages/select'
        }, {
          menuname: '我的订单',
          menuid: 2,
          menuurl: '/pages/order'
        }, {
          menuname: '投稿须知',
          menuid: 3,
          menuurl: ''
        }
      ]
    }
  },
  components: {
  },
  created() {
    window.data = this
    this.loginText = localStorage.getItem('user') || '登录/注册'
    this.loginStatus = localStorage.getItem('user') || false
  },
  methods: {
    setName(name) {
      console.log("调用了" + name);
      this.loginText = name
      this.loginStatus = true
    },
    toPage(value) {
      if (value.menuurl && value.menuurl !== this.$route.fullPath) {
        this.$router.push(value.menuurl)
      }
    },
    async logout() {
      const res = await this.$alert('确定要退出当前账户吗', '提示', {
        confirmButtonText: '确定',
        confirmButtonClass: 'tipsConfirm'
      });
      if (res === 'confirm') {
        localStorage.removeItem('token')
        localStorage.removeItem('user')
        this.loginStatus = false
        this.loginText = localStorage.getItem('user') || '登录/注册'
        window.location.href = '/'
      }
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-menu-item {
  font-size: 16px;
}
::v-deep .el-dropdown {
  font-size: 16px;
}
.header_1 {
  margin: 10px 20px 10px 15%;
  padding-right: 1%;
  width: 20%;
  height: 50px;
  position: absolute;
  float: left;
  border-right: 1px solid #aaaaaa;
}
.p1 {
  display: flex;
  font-weight: 800;
  font-size: 25px;
  font-family: 微软雅黑;
  justify-content: center;
  color: #aa0000;
  margin: 0;
  align-items: center;
}
.p2 {
  font-size: 15px;
  display: flex;
  font-family: 微软雅黑;
  font-weight: 500;
  justify-content: center;
  margin: 0;
  align-items: center;
}
.header_2 {
  margin: 10px 0 10px 33%;
  padding-right: 3%;
  width: 25%;
  height: 50px;
  position: absolute;
  float: right;
  display: flex;
  align-items: center;
  justify-content: right;
  border-right: 1px solid #aaaaaa;
}

.header_3 {
  position: absolute;
  float: left;
  width: 27%;
  height: 50px;
  text-align: center;
  margin: 10px 0 10px 58%;
  display: flex;
  justify-content: center;
  align-items: center;
  .login_box {
    // width: 160px;
    padding: 0 20px;
    height: 45px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #aa0000;
    border-radius: 20px;
    color: #fff;
    font-size: 16px;
    line-height: 1;
    i {
      margin-right: 5px;
    }
    .userText {
      max-width: 90px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
  .logoutText {
    margin-left: 10px;
    cursor: pointer;
    position: relative;
    &::before {
      content: '';
      display: block;
      width: 1px;
      height: 100%;
      position: absolute;
      left: -5px;
      top: 0;
      background-color: #cfcfcf;
    }
  }
}
.el-main {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 80vh;
  background-color: #f5f5f5;
}
.el-dropdown {
  width: 150px;
}
.el-dropdown-menu {
  width: 300px;
}
.el-button {
  height: 45px;
  background-color: #aa0000;
}
.el-menu {
  font-size: 30px;
}
.el-footer {
  width: 100%;
  height: 4vh;
  padding: 0;
}
</style>
